package com.link2room.rodimus.controller.api;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.rodimus.facade.ICouponFacadeService;
import com.link2room.rodimus.dto.param.api.*;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/7/19.14:50
 */
@Api(tags = "联房券相关")
@RestController
@RequestMapping("/api/Coupons")
public class CouponApiController {

    @Resource
    private ICouponFacadeService couponFacadeService;

    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto currentUserCouponList() throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setListToQueryResult(couponFacadeService.getCurrentCouponList(new CouponParamDto()));
        return resDto;
    }

    @RequestMapping(value = "/{couponNo}", method = RequestMethod.GET)
    public BaseResultDto couponDetail(@PathVariable("couponNo") String couponNo) throws Exception {
        CouponParamDto couponParamDto = new CouponParamDto();
        couponParamDto.setCouponNo(couponNo);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(couponFacadeService.getCouponDetail(couponParamDto));
        return resDto;
    }

    @RequestMapping(value = "/presentCoupon", method = RequestMethod.POST)
    public BaseResultDto presentCoupon(@RequestBody CouponPresentParamDto couponPresentParamDto) throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(couponFacadeService.presentCoupon(couponPresentParamDto));
        return resDto;
    }

    @RequestMapping(value = "/doDrawCoupon", method = RequestMethod.POST)
    public BaseResultDto doDrawCoupon(@RequestBody CouponDrawParamDto paramDto) throws Exception {
        couponFacadeService.drawCoupon(paramDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value = "/myPresention", method = RequestMethod.GET)
    public BaseResultDto currentUserPresentList() throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setListToQueryResult(couponFacadeService.currentUserPresentList(new BaseL2rParamDto()));
        return resDto;
    }

    @RequestMapping(value = "/rePresent", method = RequestMethod.POST)
    public BaseResultDto rePresentCoupon(@RequestBody CouponRePresentParamDto paramDto) throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(couponFacadeService.rePresentCoupon(paramDto));
        return resDto;
    }

    @RequestMapping(value = "/couponReceivedList", method = RequestMethod.GET)
    public BaseResultDto couponReceivedList(@RequestParam(name = "couponPresentNo") String couponPresentNo) throws Exception {
        CouponReceiveParamDto paramDto = new CouponReceiveParamDto();
        paramDto.setCouponPresentNo(couponPresentNo);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(couponFacadeService.listCouponReceived(paramDto));
        return resDto;
    }

    @RequestMapping(value = "/consum" , method = RequestMethod.POST)
    public BaseResultDto consumeCoupon(@RequestBody CouponConsumeParamDto consumeParamDto) throws Exception {

        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(couponFacadeService.couponConsumWithExpress(consumeParamDto));
        return resDto;
    }



    @RequestMapping(value = "/consums",method = RequestMethod.GET)
    public BaseResultDto consumes(
            @RequestParam(name = "couponCode",required = false)String couponCode,
            @RequestParam(name = "consumeSta",required = false)String consumeSta
    ) throws Exception {
        CouponConsumeParamDto consumeParamDto = new CouponConsumeParamDto();
        consumeParamDto.setCouponCode(couponCode);
        consumeParamDto.setConsumeSta(consumeSta);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setQueryResult(couponFacadeService.currentUserCouponConsumList(consumeParamDto));
        return resDto;
    }
    
    @RequestMapping(value = "/coupenCodeCollarCoupenJD",method = RequestMethod.POST)
    public BaseResultDto coupenCodeCollarCoupenJD(
            @RequestParam(name = "couponCode")String couponCode
    ) throws Exception {
    	CoupenCodeCollarCoupenParamDto codeCollarCoupenParamDto = new CoupenCodeCollarCoupenParamDto();
    	codeCollarCoupenParamDto.setCouponCode(couponCode);
    	codeCollarCoupenParamDto.setCouponCodeType("JD");
    	couponFacadeService.coupenCodeCollarCoupen(codeCollarCoupenParamDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }
}
